package com.woniuxy.config;

import com.woniuxy.dao.CampRepo;
import com.woniuxy.dao.CommentRepo;
import com.woniuxy.dao.ProductRepo;
import com.woniuxy.entity.Camp;
import com.woniuxy.entity.Product;
import com.woniuxy.service.CampService;
import com.woniuxy.service.FoodService;
import com.woniuxy.service.LiuService;
import com.woniuxy.vo.CampVO;
import com.woniuxy.vo.FoodCommentlVO;
import com.woniuxy.vo.ProductVo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Component
public class InitConfig implements InitializingBean {
    @Resource
    private CampRepo campRepo;
    @Resource
    private CampService campService;
    @Resource
    private ProductRepo productRepo;
    @Resource
    private LiuService liuService;
    @Resource
    private FoodService foodService;
    @Resource
    private CommentRepo CommentRepo;
    /*
     *  初始化的时候，将数据库信息加入elasticsearch中
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        List<CampVO> camps = campService.selectAllCampVO();
        campRepo.saveAll(camps);
        List<ProductVo> list = liuService.selectAllProductVo();
        productRepo.saveAll(list);

        List<FoodCommentlVO> commentlVOList = foodService.selectAllFoodCommentlVO();
        CommentRepo.saveAll(commentlVOList);

    }


}
